package com.bear.atlassianmcp.confluence.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;
import java.util.Map;

/**
 * Confluence搜索结果模型
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConfluenceSearchResult {

    private List<ConfluenceSearchPage> results;
    private Integer start;
    private Integer limit;
    private Integer size;
    private Integer totalSize;
    
    @JsonProperty("_links")
    private Map<String, Object> links;

    /**
     * 格式化为AI友好的文本描述
     */
    public String toFormattedString() {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("🔍 搜索结果 (共%d个，显示%d个)：\n\n", 
                                totalSize != null ? totalSize : 0, 
                                size != null ? size : 0));
        
        if (results != null && !results.isEmpty()) {
            for (int i = 0; i < results.size(); i++) {
                ConfluenceContent page = results.get(i).getContent();
                sb.append(String.format("%d. %s\n", i + 1, page.getTitle()));
                sb.append(String.format("   📁 空间: %s\n", 
                                       page.getSpace() != null ? page.getSpace().getName() : "未知"));
                sb.append(String.format("   🆔 ID: %s\n", page.getId()));
                sb.append(String.format("   📊 状态: %s\n", page.getStatus()));
                sb.append(String.format("   📝 内容预览: %s\n", results.get(i).getExcerpt()));
                sb.append("\n");
            }
        } else {
            sb.append("没有找到匹配的页面。\n");
        }
        
        return sb.toString();
    }

    // Getters and Setters
    public List<ConfluenceSearchPage> getResults() {
        return results;
    }

    public void setResults(List<ConfluenceSearchPage> results) {
        this.results = results;
    }

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Integer getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(Integer totalSize) {
        this.totalSize = totalSize;
    }

    public Map<String, Object> getLinks() {
        return links;
    }

    public void setLinks(Map<String, Object> links) {
        this.links = links;
    }
}
